<template>
	<view class="news tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed>内容列表</tn-nav-bar>

		<!-- 文章分类开始 -->
		<view class="" :style="{paddingTop: (vuex_custom_bar_height -10) + 'px'}">
			<view class="tn-margin-top">
				<tn-tabs :list="cateList" name="title" :current="current" backgroundColor="tn-main-gradient-indigo"
					activeColor="#FFFFFF" @change="tabChange"></tn-tabs>
			</view>
		</view>
		<!-- 文章分类结束 -->

		<!-- 文章列表开始 -->
		<view class="" style="padding-bottom: 60rpx;" v-if="articleList.length  > 0">
			<view class="">
				<block v-for="(item, index) in articleList" :key="index">
					<view class="article-shadow tn-margin-top tn-margin-bottom tn-bg-white"
						@click="tn('/subpages/article/content?uid=' + item.uid)">
						<view class="tn-flex">
							<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
								<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
									<text class="">{{ item.title }}</text>
								</view>
								<view class="tn-padding-top-xs" style="min-height: 90rpx;">
									<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
										{{ item.desc }}
									</text>
								</view>
								<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
									<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
										<text class="tn-tag-content__item--prefix">#</text> {{ item.category.title }}
									</view>
									<view class="justify-content-item tn-color-gray tn-text-center" style="padding-top: 5rpx;">
										<text class="tn-icon-eye tn-padding-right-xs tn-text-lg tn-color-gray"></text>
										<text class="tn-padding-right tn-text-df">{{ item.click_actual }}</text>
										<text class="tn-icon-like-lack tn-padding-right-xs tn-text-lg tn-color-gray"></text>
										<text class="tn-text-df">{{ item.collect_count }}</text>
									</view>
								</view>
							</view>
							<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.image + ')'">
								<view class="image-article">
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<tn-load-more :status="loadStatus"></tn-load-more>
		</view>
		<!-- 文章列表结束 -->
		<!-- 内容为空开始 -->
		<view class="" v-if="cateList.length==0">
			<view class="" style="padding: 20vh 20rpx;">
				<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
					<text class="tn-icon-empty-page tn-color-gray--light"></text>
				</view>
				<view class="tn-color-gray--disabled tn-text-center tn-text-lg" @click="tn('/subpages/help/content?uid=482928805799789437')">
					<tn-button fontColor="#fff" backgroundColor="#01BEFF" height="100rpx" shape="round" width="100%">请仔细阅读答题规范</tn-button>
				</view>
			</view>
		</view>
		<!-- 内容为空结束 -->

		<view class='tn-tabbar-height'></view>


	</view>
</template>

<script>
	import {
		getArtcileList,
		getArticleCateList
	} from "@/utils/api/article.js"
	export default {
		name: 'News',
		data() {
			return {
				loadStatus: "loading",
				articleList: [],
				searchWhere: {
					currentPage: 1,
					perSize: 20,
					cate_uid: "",
				},
				current: 0,
				cateList: [],
			}
		},
		onLoad() {
			this.getArticleCateList()
		},
		methods: {
			// tab选项卡切换
			tabChange(index) {
				this.current = index
				this.searchWhere.cate_uid = this.cateList[index].uid
				this.articleList = []
				this.searchWhere.currentPage = 1
				this.getArtcileList()
			},
			// 获取文章分类
			getArticleCateList() {
				getArticleCateList().then(res => {
					this.cateList = res.data
					this.searchWhere.cate_uid = res.data[0].uid
					this.getArtcileList()
				})
			},
			// 获取文章列表
			getArtcileList() {
				uni.showLoading({
					title: "努力加载中",
					icon: "none",
					mask: false,
				})
				getArtcileList(this.searchWhere).then(res => {
					uni.hideLoading()
					if (res.code == 100) {
						this.articleList.push(...res.data.items)
						this.searchWhere.currentPage = res.data.currentPage + 1
						this.loadStatus = res.data.items == 0 ? "nomore" : "loadmore"
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		},
		onReachBottom() {
			this.getArtcileList()
		}
	}
</script>

<style lang="scss" scoped>
	.news {
		max-height: 100vh;
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 镂空 */
	.tnloukong {
		position: fixed;
		padding: 4rpx 8rpx;
		bottom: 220rpx;
		border-radius: 5rpx;
		left: 30rpx;
		font-weight: bold;
		text-align: center;
		z-index: 1000;
		background: rgba(255, 255, 255, 1);
		color: #070707;
		/* mix-blend-mode: overlay; difference;lighten;hue*/
		mix-blend-mode: lighten;

	}

	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		width: 200rpx;
		height: 200rpx;
		position: relative;
	}

	.image-pic {
		border: 1rpx solid #F8F7F8;
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	.article-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 35rpx;
			color: #1D2541;
			background-color: #F3F2F7;
			border-radius: 10rpx;
			font-size: 22rpx;
			padding: 5rpx 15rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}


	/* 大单图 start*/
	.tn-blogger-content2 {
		&__wrap {
			padding: 30rpx;
		}

		&__info {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}

		&__label {
			&__item {
				line-height: 45rpx;
				padding: 0 20rpx;
				margin: 5rpx 18rpx 0 0;

				&--prefix {
					color: #00FFC8;
					padding-right: 10rpx;
				}
			}

			&__desc {
				line-height: 55rpx;
			}
		}

		&__main-image {
			box-shadow: 0rpx 5rpx 40rpx 0rpx rgba(43, 158, 246, 0.2);
			border-radius: 16rpx;

			&--1 {
				max-width: 690rpx;
				min-width: 690rpx;
				max-height: 400rpx;
				min-height: 400rpx;
			}

			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}

			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}

		&__count-icon {
			font-size: 40rpx;
			padding-right: 5rpx;
		}
	}

	.image-design {
		padding: 140rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	/* 文章内容 end*/
</style>